package com.wiscamp.ninechapters.problems.math;

import com.wiscamp.ninechapters.common.core.ParseHelper;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.math.BigDecimal;

/**
 * 小数范围
 */
@Data
@EqualsAndHashCode(callSuper = true)
public class LatexDecimalRange extends LatexNumberRange {
    /**
     * 起始小数
     */
    private BigDecimal begin;

    /**
     * 结束小数
     */
    private BigDecimal end;

    public String getLatex() {
        return String.format("%f-%f", begin.stripTrailingZeros(), end.stripTrailingZeros());
    }

    public LatexDecimalRange(BigDecimal begin, BigDecimal end) {
        this.begin = begin;
        this.end = end;
    }

    public LatexDecimalRange(String beginValueText, String endValueText) {
        this.begin = ParseHelper.parseBigDecimal(beginValueText);
        this.end = ParseHelper.parseBigDecimal(endValueText);
    }

    public LatexDecimalRange(String content) {
        var array = content.split("-");
        if (array.length == 2) {
            this.begin = ParseHelper.parseBigDecimal(array[0]);
            this.end = ParseHelper.parseBigDecimal(array[1]);
        }
    }
}
